<?php
// 更改信息
// header("content-type:text/html;charset=utf-8");
include_once("conn.php");
if (!session_id()) {
    session_start();
}
//时区设置为中国
date_default_timezone_set('PRC');

if (!empty($_POST['action'])) {
    $uid = $_POST['uid'];
    if ($_POST['action'] == 'base') {
        $uname = $_POST['uname'];
        $uphone = $_POST['uphone'];
        $sql = "UPDATE tb_user_info SET uname='" . $uname . "',uphone='" . $uphone . "' WHERE uid='" . $uid . "'";
        $result = mysqli_query($conn, $sql);
        if ($result) {
            $sql_1 = "SELECT * FROM tb_user_info WHERE uid ='" . $uid . "'";
            $result_1 = mysqli_query($conn, $sql_1);
            if ($result_1) {
                $info = mysqli_fetch_assoc($result_1);
                $_SESSION['USERINFOS'] = $info;
                echo "<script>alert('修改成功！');window.location.href='../u_personal_info.php';</script>";
            }
        }else{
            echo "<script>alert('修改失败！');history.go(-1);</script>";
        }
    }

    if ($_POST['action'] == 'login') {
        $oldpwd = $_POST['old_pwd'];
        if($oldpwd != $_SESSION['USERINFOS']['upwd']){
            echo "<script>alert('原密码错误！');history.go(-1);</script>";
        }
        $newpwd = $_POST['new_pwd'];
        $sql = "UPDATE tb_user_info SET upwd='" . $newpwd . "' WHERE uid='" . $uid . "'";
        $result = mysqli_query($conn, $sql);
        if ($result) {
            echo "<script>alert('修改成功！请重新登录！');</script>";
            include_once("logout.php");
        }else{
            echo "<script>alert('修改失败！');history.go(-1);</script>";
        }
    }
}
